#include "CEnemyType2.h"
#include "MainLayer.h"

CEnemyType2::CEnemyType2(CEnemyParams enemyParams) : CEnemy(enemyParams)
{
}

void
CEnemyType2::createBoxBodyForSize(CEnemyParams::EEnemySize size)
{
	CEnemy::createBoxBody();

	switch(size)
	{
	case CEnemyParams::size1:
		createBoxBodySize1();
		break;
	case CEnemyParams::size2:
		createBoxBodySize2();
		break;
	case CEnemyParams::size3:
		createBoxBodySize3();
		break;
	case CEnemyParams::size4:
		createBoxBodySize4();
		break;
	default:
		break;
	}
}

void
CEnemyType2::createBoxBodySize1()
{
	b2PolygonShape spriteShape;
	int num = 5;
	b2Vec2 verts[] = {
			b2Vec2(-8.3393f / P2M, -20.3268f / P2M),
			b2Vec2(35.8673f / P2M, -19.6568f / P2M),
			b2Vec2(34.1933f / P2M, 19.8612f / P2M),
			b2Vec2(-12.0225f / P2M, 13.4980f / P2M),
			b2Vec2(-39.4845f / P2M, -2.9120f / P2M)
	};

	spriteShape.Set(verts, num);

	b2FixtureDef spriteShapeDef;
	spriteShapeDef.shape = &spriteShape;
	spriteShapeDef.density = 1.0f;
	spriteShapeDef.restitution = 0.5f;
	spriteShapeDef.filter.categoryBits = ECategoryBit::enemyCategoryBit;
	spriteShapeDef.filter.maskBits = ECategoryBit::bulletCategoryBit |
									  ECategoryBit::shipCategoryBit |
									  ECategoryBit::shieldCategoryBit;

	_pBody->CreateFixture(&spriteShapeDef);
}

void
CEnemyType2::createBoxBodySize2()
{
	b2PolygonShape spriteShape;
	int num = 5;
	b2Vec2 verts[] = {
			b2Vec2(-12.2909f / P2M, -22.4699f / P2M),
			b2Vec2(45.5793f / P2M, -22.8717f / P2M),
			b2Vec2(42.3643f / P2M, 26.1572f / P2M),
			b2Vec2(-11.4874f / P2M, 18.9233f / P2M),
			b2Vec2(-48.8613f / P2M, -2.3760f / P2M)
	};

	spriteShape.Set(verts, num);

	b2FixtureDef spriteShapeDef;
	spriteShapeDef.shape = &spriteShape;
	spriteShapeDef.density = 1.0f;
	spriteShapeDef.restitution = 0.5f;
	spriteShapeDef.filter.categoryBits = ECategoryBit::enemyCategoryBit;
	spriteShapeDef.filter.maskBits = ECategoryBit::bulletCategoryBit |
									  ECategoryBit::shipCategoryBit |
									  ECategoryBit::shieldCategoryBit;

	_pBody->CreateFixture(&spriteShapeDef);
}

void
CEnemyType2::createBoxBodySize3()
{
	b2PolygonShape spriteShape;
	int num = 5;
	b2Vec2 verts[] = {
			b2Vec2(-12.7728f / P2M, -28.1766f / P2M),
			b2Vec2(54.2601f / P2M, -27.6946f / P2M),
			b2Vec2(51.3664f / P2M, 31.6228f / P2M),
			b2Vec2(-15.6665f / P2M, 21.9775f / P2M),
			b2Vec2(-58.1052f / P2M, -2.6172f / P2M)
	};

	spriteShape.Set(verts, num);

	b2FixtureDef spriteShapeDef;
	spriteShapeDef.shape = &spriteShape;
	spriteShapeDef.density = 1.0f;
	spriteShapeDef.restitution = 0.5f;
	spriteShapeDef.filter.categoryBits = ECategoryBit::enemyCategoryBit;
	spriteShapeDef.filter.maskBits = ECategoryBit::bulletCategoryBit |
									  ECategoryBit::shipCategoryBit |
									  ECategoryBit::shieldCategoryBit;

	_pBody->CreateFixture(&spriteShapeDef);
}

void
CEnemyType2::createBoxBodySize4()
{
	b2PolygonShape spriteShape;
	int num = 5;
	b2Vec2 verts[] = {
			b2Vec2(-17.5959f / P2M, -32.9990f / P2M),
			b2Vec2(63.4223f / P2M, -32.9990f / P2M),
			b2Vec2(60.5299f / P2M, 34.9982f / P2M),
			b2Vec2(-20.9718f / P2M, 23.4246f / P2M),
			b2Vec2(-66.3030f / P2M, -4.0644f / P2M)
	};

	spriteShape.Set(verts, num);

	b2FixtureDef spriteShapeDef;
	spriteShapeDef.shape = &spriteShape;
	spriteShapeDef.density = 1.0f;
	spriteShapeDef.restitution = 0.5f;
	spriteShapeDef.filter.categoryBits = ECategoryBit::enemyCategoryBit;
	spriteShapeDef.filter.maskBits = ECategoryBit::bulletCategoryBit |
									  ECategoryBit::shipCategoryBit |
									  ECategoryBit::shieldCategoryBit;

	_pBody->CreateFixture(&spriteShapeDef);
}
